<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String manager_id=request.getParameter("manager_id");
System.out.println(manager_id);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   	<jsp:include page="../inc/meta.jsp"></jsp:include>
	<jsp:include page="../inc/easyui.jsp"></jsp:include>
	<script type="text/javascript">
		var datagrid = null;
		var role_ids=[];
		$(function(){
			datagrid = $("#roleList").datagrid({
				url : "../role/roleList",
				loadMsg : "数据加载中请稍后……",
				iconCls : "icon-save",
				sortName : "role_id",
				sortOrder : "desc",
				fit : true,
				striped : true,
				autoRowHeight : false,
				pagination : true,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50, 60 ],
				idField : "role_id",
				nowrap : false,
				fitColumns : true,
				singleSelect : true,//单行选中
				rownumbers : true,//显示行索引
				columns : [ [ {
					field : "chk",
					title : "",
					align : "center",
					width : 100,
					checkbox : true
				},{
					field : "role_id",
					title : "角色编号",
					align : "center",
					width : 60
				}, {
					field : "role_name",
					title : "角色名称",
					align : "center",
					width : 150
				}, {
					field : "status",
					title : "状态",
					align : "center",
					width : 80,
					formatter : function(value, rowData, rowIndex) {
						if (value == 0) {
							return "正常";
						} else {
							return "禁用";
						}
					}
				}, {
					field : "create_time",
					title : "创建时间",
					align : "center",
					width : 120,
					formatter:function(value){
						if(value==null){
							return;
						}else{
							return formatDate(new Date(value));
						}
					}
				}] ],
	 			toolbar : '#toolbar',
				onBeforeLoad : function(row, param) {
				$.ajax({
					url : "../role/findRoleIdByManagerId",
					data : {manager_id : $("#m_id").val()},
					dataType : 'json',
					type : 'post',
					success : function(obj)
					{
						// var data = eval('(' + obj + ')');
                        var data = obj;
						$.each(data,function(i,ite){
							role_ids.push(ite.role_id)
						})
					}
				})
					parent.$.messager.progress({
						text : '数据加载中....'
					});
				},
				onLoadSuccess : function(data) {
					for(var i=0;i<role_ids.length;i++)
					{
						datagrid.datagrid('selectRecord',role_ids[i]);
					}
				
					$('.iconImg').attr('src', sy.pixel_0);
					parent.$.messager.progress('close');
				}
			});
		});
		
	function searchFun(){
		datagrid.datagrid("load",serializetoObject($("#queryForm").form()));
	}
	
	function clearFun() {
		$('#queryForm input').val('');
		datagrid.datagrid('load', {});
	}
	
	var assignF = function($dialog,$datagrid,$managerid,$parent){
		var ids=[];
		var rows = datagrid.datagrid("getSelections");
		if(rows.length==0){
			$.messager.alert('提示',"请选择要分配的角色！");
		}else{
			for(var i=0;i<rows.length;i++)
			{
				ids.push(rows[i].role_id);
			}
			$.ajax({
				url : "../manager/assignrole",
				data : {
					managerid : $managerid,roleids:ids.join(',')
				},
				cache : false,
				dataType : "json",
				success : function(data) {
					if (data.success) {
						$dialog.dialog('destroy');
					}
					$parent.messager.alert('提示', data.msg, 'info');
					datagrid.datagrid('unselectAll');
					datagrid.datagrid('reload');
				}
			});
		}
	};
	</script>
</head>
<body class="easyui-layout" fit="true">
	<div id="toolbar" style="display: none;">
		<form id="queryForm" action="#" method="post">
			<table>
				<tr>
					<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addFun();">添加</a></td>
					<td><div class="datagrid-btn-separator"></div></td>
					<td><input name="role_name" class="easyui-searchbox" style="width: 150px" data-options="searcher:searchFun"></input></td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-zoom_out',plain:true" onclick="clearFun();">清空查询</a></td>
				</tr>
			</table>
		</form>
	</div>
	<div region="center" border="false" style="overflow: hidden;">
		<input type="hidden" id="m_id" value="<%=manager_id%>"/>
		<table id="roleList" fit="true" border="false"></table>
	</div>
  </body>
</html>
